﻿using Core.Configuration;
using Core.Domain.Configuration;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace Services.Configuration
{
    public partial interface ISettingService
    {
        /// <summary>
        /// 根据主键获取设置信息
        /// </summary>
        /// <param name="settingId"></param>
        /// <returns></returns>
        Setting GetSettingById(int settingId);

        /// <summary>
        /// 删除设置信息
        /// </summary>
        /// <param name="setting"></param>
        void DeleteSetting(Setting setting);

        /// <summary>
        /// 根据关键字获取设置信息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="defaultValue"></param>
        /// <param name="storeId"></param>
        /// <param name="loadSharedValueIfNotFound"></param>
        /// <returns></returns>
        T GetSettingByKey<T>(string key, T defaultValue = default(T),
            int storeId = 0, bool loadSharedValueIfNotFound = false);

        /// <summary>
        /// 根据关键字设置设置信息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="storeId"></param>
        /// <param name="clearCache"></param>
        void SetSetting<T>(string key, T value, int storeId = 0);

        /// <summary>
        /// 获取设置信息
        /// </summary>
        /// <returns></returns>
        IList<Setting> GetAllSettings();

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TPropType"></typeparam>
        /// <param name="settings"></param>
        /// <param name="keySelector"></param>
        /// <param name="storeId"></param>
        /// <returns></returns>
        bool SettingExists<T, TPropType>(T settings,
            Expression<Func<T, TPropType>> keySelector, int storeId = 0)
            where T : ISettings, new();

        /// <summary>
        /// 读取设置信息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="storeId"></param>
        /// <returns></returns>
        T LoadSetting<T>(int storeId = 0) where T : ISettings, new();

        /// <summary>
        /// 存储设置信息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="settings"></param>
        /// <param name="storeId"></param>
        void SaveSetting<T>(T settings, int storeId = 0) where T : ISettings, new();

        /// <summary>
        /// 存储设置信息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TPropType"></typeparam>
        /// <param name="settings"></param>
        /// <param name="keySelector"></param>
        /// <param name="storeId"></param>
        /// <param name="clearCache"></param>
        void SaveSetting<T, TPropType>(T settings,
            Expression<Func<T, TPropType>> keySelector,
            int storeId = 0) where T : ISettings, new();

        /// <summary>
        /// 删除设置信息
        /// </summary>
        /// <typeparam name="T"></typeparam>        
        void DeleteSetting<T>() where T : ISettings, new();

        /// <summary>
        /// 删除设置信息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TPropType"></typeparam>
        /// <param name="settings"></param>
        /// <param name="keySelector"></param>
        /// <param name="storeId"></param>
        void DeleteSetting<T, TPropType>(T settings,
            Expression<Func<T, TPropType>> keySelector, int storeId = 0) where T : ISettings, new();

    }
}
